package containerlogistik.implementation;

import static com.google.common.base.Preconditions.*;
import containerlogistik.interfaces.BoundingBox;
import containerlogistik.interfaces.Container;
import containerlogistik.interfaces.ContainerTruck;
import containerlogistik.interfaces.Length;
import containerlogistik.interfaces.Level;
import containerlogistik.interfaces.Mass;
import containerlogistik.interfaces.Power;
import containerlogistik.interfaces.StowageLocation;
import containerlogistik.interfaces.TimeDiff;
import java.util.Collection;
import java.util.Set;

public class ContainerTruckImpl extends AbstractContainerCar implements ContainerTruck {
    
    private ContainerTruckImpl(Mass mass, Mass emptyMass, Mass maxMass, BoundingBox boundingBox, Length pos, Power power, Power maxPower, Level level) {
        this.mass = mass;
        this.emptyMass = emptyMass;
        this.maxMass = maxMass;
        this.boundingBox = boundingBox;
        this.pos = pos;
        this.power = power;
        this.maxPower = maxPower;
        this.level = level;
    }
    
    static ContainerTruck valueOf(Mass mass, Mass emptyMass, Mass maxMass, BoundingBox boundingBox, Length pos, Power power, Power maxPower, Level level) {
        return new ContainerTruckImpl(mass, emptyMass, maxMass, boundingBox, pos, power, maxPower, level);
    }

    @Override
    public Length pos() {
        return this.pos;
    }

    @Override
    public Power power() {
        return this.power;
    }

    @Override
    public Power maxPower() {
        return this.maxPower;
    }

    @Override
    public void setLevel(int level) {
        this.level = Values.levelOfPedal(level);
    }

    @Override
    public void moveStep(TimeDiff deltaTime) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Mass emptyMass() {
        return this.emptyMass;
    }

    @Override
    public Mass maxMass() {
        return this.maxMass;
    }

    @Override
    public boolean isEmpty() {
        return this.container.isFree();
    }

    @Override
    public boolean isFull() {
        return this.container.isOccupied();
    }

    @Override
    public void load(int bayNo, int rowNo, Container elem) {
        checkArgument(bayNo < 1 && rowNo < 1, "Cannot load this element to a not existing place.");
        checkArgument(bayNo >= 0 && rowNo >= 0, "Bay and row must be positive.");
        this.load(elem);
    }

    @Override
    public void load(Container elem) {
        checkArgument(!this.isFull(), "Cannot load this element, because the stack ist full.");
        this.container = elem;
    }

    @Override
    public void loadAll(Collection<? extends Container> coll) {
        checkArgument(coll.size() <= 1, "Cannot load more than one element.");
        checkArgument(coll.isEmpty(), "There are no elements to load.");
        for(Container elem : coll) {
            this.container = elem;
        }
    }

    @Override
    public boolean tierIsEmpty(int bay, int row) {
        if(bay < 1 && bay >= 0 && row < 1&& row >= 0) {
            return this.isEmpty();
        }
        return false;
    }

    @Override
    public boolean tierIsFull(int bay, int row) {
        if(bay < 1 && bay >= 0 && row < 1&& row >= 0) {
            return this.isFull();
        }
        return true;
    }

    @Override
    public boolean contains(Object elem) {
        return this.container.equals(elem);
    }

    @Override
    public boolean containsAll(Collection<?> coll) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Container get(StowageLocation loc) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Set<Container> getAll() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public StowageLocation locationOf(Container elem) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
